home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD-ROM Today - The Disc! 5
/
CD-ROM Today - The Disc (Issue 5)(November 1994).ISO
/
mac
/
Mac shareware
/
Education
/
RLaB
/
rlib
/
cross.r
< prev
next >
Wrap
Text File
|
1994-09-21
|
604b
|
27 lines
//-------------------------------------------------------------------//
// Syntax: cross ( A , B )
//
// Description:
// Given A and B (two 1-by-3 matrices), compute the vector
// cross-product.
//-------------------------------------------------------------------//
cross = function(v1, v2)
{
local(i, tmp);
if(v1.n != 3 || v2.n != 3)
{
printf("cross product requires 3-length matrices\n");
return 0;
}
tmp = zeros(1,3);
tmp[1] = ((v1[2]*v2[3]) - (v1[3]*v2[2]));
tmp[2] = -((v1[1]*v2[3]) - (v1[3]*v2[1]));
tmp[3] = ((v1[1]*v2[2]) - (v1[2]*v2[1]));
return tmp;
};